<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>JPA总结 | Jeremy Sze的博客</title>
    <meta property="og:title" content="JPA总结 - Jeremy Sze的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2018-10-19T08:36:54&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2018-10-19T08:36:54&#43;08:00'>
        
    <meta name="Keywords" content="java,博客">
    <meta name="description" content="JPA总结">
        
    <meta name="author" content="Jeremy Sze">
    <meta property="og:url" content="https://laoer123.gitee.io/laoer123/post/JPA/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href='/laoer123/css/normalize.css'>
    <link rel="stylesheet" href='/laoer123/css/style.css'>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({
        google_ad_client: "ca-pub-4031353640611810",
        enable_page_level_ads: true
    });
    </script>
    


    
    
        <link rel="stylesheet" href='/laoer123/css/douban.css'>
    
        <link rel="stylesheet" href='/laoer123/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://laoer123.gitee.io/laoer123">
                        Jeremy Sze的博客
                    </a>
                
                <p class="description">专注于Java、JavaScript、软件开发、web开发、分布式，微服务系统开发</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://laoer123.gitee.io/laoer123">首页</a>
                    
                    <a  href="https://laoer123.gitee.io/laoer123/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#orm概述及特点">ORM概述及特点</a>
      <ul>
        <li><a href="#概述">概述</a></li>
        <li><a href="#特点">特点</a></li>
      </ul>
    </li>
    <li><a href="#为什么使用orm">为什么使用ORM</a></li>
    <li><a href="#常见orm框架">常见ORM框架</a></li>
    <li><a href="#hibernate与jpa的概述了解">hibernate与JPA的概述[了解]</a>
      <ul>
        <li><a href="#hibernate概述">hibernate概述</a></li>
        <li><a href="#jpa概述">JPA概述</a></li>
        <li><a href="#jpa的优势">JPA的优势</a></li>
      </ul>
    </li>
    <li><a href="#jpa与hibernate的关系">JPA与hibernate的关系</a></li>
    <li><a href="#编写实体类和数据库表的映射配置">编写实体类和数据库表的映射配置</a>
      <ul>
        <li><a href="#在实体类上使用jpa注解的形式配置映射关系">在实体类上使用JPA注解的形式配置映射关系</a></li>
      </ul>
    </li>
    <li><a href="#常用注解的说明">常用注解的说明</a></li>
    <li><a href="#配置jpa的核心配置文件">配置JPA的核心配置文件</a>
      <ul>
        <li><a href="#实现保存操作">实现保存操作</a></li>
        <li><a href="#jpa中的主键生成策略">JPA中的主键生成策略</a></li>
      </ul>
    </li>
    <li><a href="#jpa的api介绍">JPA的API介绍</a>
      <ul>
        <li><a href="#persistence对象">Persistence对象</a></li>
        <li><a href="#entitymanagerfactory">EntityManagerFactory</a></li>
        <li><a href="#entitymanager">EntityManager</a></li>
        <li><a href="#entitytransaction">EntityTransaction</a></li>
      </ul>
    </li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">JPA总结</h1>
        </header>
        <date class="post-meta meta-date">
            2018年10月19日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='https://laoer123.gitee.io/categories/%E6%95%B0%E6%8D%AE%E5%B1%82%E6%A1%86%E6%9E%B6'>数据层框架</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <h2 id="orm概述及特点">ORM概述及特点</h2>
<h3 id="概述">概述</h3>
<p>  ORM（Object-Relational Mapping） 表示对象关系映射。在面向对象的软件开发中，通过ORM，就可以把对象映射到关系型数据库中。只要有一套程序能够做到建立对象与数据库的关联，操作对象就可以直接操作数据库数据，就可以说这套程序实现了ORM对象关系映射<br>
$\color{red}{简单的说：ORM就是建立实体类和数据库表之间的关系，从而达到操作实体类就相当于操作数据库表的目的。}$</p>
<h3 id="特点">特点</h3>
<p>  通过操作对象就可以操作数据库并实现数据库的增删改查，大大减少了重复性代码，真正的全自动化ORM框架不用写sql语句， 像mybatis只能只能称为半自动化的ORM框架，因为需要写sql语句</p>
<h2 id="为什么使用orm">为什么使用ORM</h2>
<p>  当实现一个应用程序时（不使用O/R Mapping），我们可能会写特别多数据访问层的代码，从数据库保存数据、修改数据、删除数据，而这些代码都是重复的。而使用ORM则会大大减少重复性代码。对象关系映射（Object Relational Mapping，简称ORM），$\color{red}{主要实现程序对象到关系数据库数据的映射。}$</p>
<h2 id="常见orm框架">常见ORM框架</h2>
<p>常见的orm框架： Hibernate、OpenJpa、Toplink</p>
<h2 id="hibernate与jpa的概述了解">hibernate与JPA的概述[了解]</h2>
<h3 id="hibernate概述">hibernate概述</h3>
<p>  Hibernate是一个开放源代码的对象关系映射框架，它对JDBC进行了非常轻量级的对象封装，它将POJO与数据库表建立映射关系，是一个全自动的orm框架，hibernate可以自动生成SQL语句，自动执行，使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库。</p>
<h3 id="jpa概述">JPA概述</h3>
<p>  JPA的全称是Java Persistence API， 即Java 持久化API，是SUN公司推出的一套基于ORM的规范，内部是由一系列的接口和抽象类构成。</p>
<p>  JPA通过JDK 5.0注解描述对象－关系表的映射关系，并将运行期的实体对象持久化到数据库中</p>
<h3 id="jpa的优势">JPA的优势</h3>
<h4 id="1-标准化">1. 标准化</h4>
<p>  JPA 是 JCP 组织发布的 Java EE 标准之一，因此任何声称符合 JPA 标准的框架都遵循同样的架构，提供相同的访问API，这保证了基于JPA开发的企业应用能够经过少量的修改就能够在不同的JPA框架下运行。</p>
<h4 id="2-容器级特性的支持">2. 容器级特性的支持</h4>
<p>  JPA框架中支持大数据集、事务、并发等容器级事务，这使得 JPA 超越了简单持久化框架的局限，在企业应用发挥更大的作用。</p>
<h4 id="3-简单方便">3. 简单方便</h4>
<p>  JPA的主要目标之一就是提供更加简单的编程模型：在JPA框架下创建实体和创建Java 类一样简单，没有任何的约束和限制，只需要使用 javax.persistence.Entity进行注释，JPA的框架和接口也都非常简单，没有太多特别的规则和设计模式的要求，开发者可以很容易的掌握。JPA基于非侵入式原则设计，因此可以很容易的和其它框架或者容器集成</p>
<h4 id="4-查询能力">4. 查询能力</h4>
<p>  JPA的查询语言是面向对象而非面向数据库的，它以面向对象的自然语法构造查询语句，可以看成是Hibernate HQL的等价物。JPA定义了独特的JPQL（Java Persistence Query Language），JPQL是EJB QL的一种扩展，它是针对实体的一种查询语言，操作对象是实体，而不是关系数据库的表，而且能够支持批量更新和修改、JOIN、GROUP BY、HAVING 等通常只有 SQL 才能够提供的高级查询特性，甚至还能够支持子查询。</p>
<h4 id="5-高级特性">5. 高级特性</h4>
<p>  JPA 中能够支持面向对象的高级特性，如类之间的继承、多态和类之间的复杂关系，这样的支持能够让开发者最大限度的使用面向对象的模型设计企业应用，而不需要自行处理这些特性在关系数据库的持久化。</p>
<h2 id="jpa与hibernate的关系">JPA与hibernate的关系</h2>
<p>JPA规范本质上就是一种ORM规范，注意不是ORM框架——因为JPA并未提供ORM实现，它只是制订了一些规范，提供了一些编程的API接口，但具体实现则由服务厂商来提供实现
<img src="/img/jpa.png" alt="alt jpa">
<img src="/img/jpa%E4%B8%8Ehibernate.png" alt="alt jpa">
  JPA和Hibernate的关系就像JDBC和JDBC驱动的关系，JPA是规范，Hibernate除了作为ORM框架之外，它也是一种JPA实现。JPA怎么取代Hibernate呢？JDBC规范可以驱动底层数据库吗？答案是否定的，$\color{red}{也就是说，如果使用JPA规范进行数据库操作，底层需要hibernate作为其实现类完成数据持久化工作。}$</p>
<h2 id="编写实体类和数据库表的映射配置">编写实体类和数据库表的映射配置</h2>
<h3 id="在实体类上使用jpa注解的形式配置映射关系">在实体类上使用JPA注解的形式配置映射关系</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">75
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">*		* 所有的注解都是使用JPA的规范提供的注解，
</span><span style="color:#998;font-style:italic"> *		* 所以在导入注解包的时候，一定要导入javax.persistence下的
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#3c5d5d;font-weight:bold">@Entity</span> <span style="color:#998;font-style:italic">//声明实体类
</span><span style="color:#998;font-style:italic"></span><span style="color:#3c5d5d;font-weight:bold">@Table</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cst_customer&#34;</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#998;font-style:italic">//建立实体类和表的映射关系
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Customer</span> <span style="color:#000;font-weight:bold">{</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Id</span><span style="color:#998;font-style:italic">//声明当前私有属性为主键
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy<span style="color:#000;font-weight:bold">=</span>GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">IDENTITY</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#998;font-style:italic">//配置主键的生成策略
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_id&#34;</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#998;font-style:italic">//指定和表中cust_id字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_name&#34;</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#998;font-style:italic">//指定和表中cust_name字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custName<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_source&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#998;font-style:italic">//指定和表中cust_source字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custSource<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_industry&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#998;font-style:italic">//指定和表中cust_industry字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custIndustry<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_level&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#998;font-style:italic">//指定和表中cust_level字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custLevel<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_address&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#998;font-style:italic">//指定和表中cust_address字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custAddress<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#3c5d5d;font-weight:bold">@Column</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;cust_phone&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#998;font-style:italic">//指定和表中cust_phone字段的映射关系
</span><span style="color:#998;font-style:italic"></span>	<span style="color:#000;font-weight:bold">private</span> String custPhone<span style="color:#000;font-weight:bold">;</span>
	
	<span style="color:#000;font-weight:bold">public</span> Long <span style="color:#900;font-weight:bold">getCustId</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custId<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustId</span><span style="color:#000;font-weight:bold">(</span>Long custId<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custId</span> <span style="color:#000;font-weight:bold">=</span> custId<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custName<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustName</span><span style="color:#000;font-weight:bold">(</span>String custName<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custName</span> <span style="color:#000;font-weight:bold">=</span> custName<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustSource</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custSource<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustSource</span><span style="color:#000;font-weight:bold">(</span>String custSource<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custSource</span> <span style="color:#000;font-weight:bold">=</span> custSource<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustIndustry</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custIndustry<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustIndustry</span><span style="color:#000;font-weight:bold">(</span>String custIndustry<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custIndustry</span> <span style="color:#000;font-weight:bold">=</span> custIndustry<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustLevel</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custLevel<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustLevel</span><span style="color:#000;font-weight:bold">(</span>String custLevel<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custLevel</span> <span style="color:#000;font-weight:bold">=</span> custLevel<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustAddress</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custAddress<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustAddress</span><span style="color:#000;font-weight:bold">(</span>String custAddress<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custAddress</span> <span style="color:#000;font-weight:bold">=</span> custAddress<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> String <span style="color:#900;font-weight:bold">getCustPhone</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">return</span> custPhone<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">setCustPhone</span><span style="color:#000;font-weight:bold">(</span>String custPhone<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">custPhone</span> <span style="color:#000;font-weight:bold">=</span> custPhone<span style="color:#000;font-weight:bold">;</span>
	<span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><h2 id="常用注解的说明">常用注解的说明</h2>
<p>@Entity<br>
   作用：指定当前类是实体类。<br>
@Table<br>
   作用：指定实体类和表之间的对应关系。<br>
   属性：<br>
   name：指定数据库表的名称
@Id<br>
   作用：指定当前字段是主键。<br>
@GeneratedValue<br>
   作用：指定主键的生成方式。<br>
   属性：<br>
   strategy ：指定主键生成策略。<br>
@Column<br>
   作用：指定实体类属性和数据库表之间的对应关系<br>
   属性：<br>
   name：指定数据库表的列名称。<br>
   unique：是否唯一 <br>
   nullable：是否可以为空 <br>
   inserttable：是否可以插入 <br>
   updateable：是否可以更新 <br>
   columnDefinition: 定义建表时创建此列的DDL <br>
   secondaryTable: 从表名。如果此列不建在主表上（默认建在主表），该属性定义该列所在从表的名字搭建开发环境</p>
<h2 id="配置jpa的核心配置文件">配置JPA的核心配置文件</h2>
<p>$\color{red}{在java工程的src路径下resources创建一个名为META-INF的文件夹，在此文件夹下创建一个名为persistence.xml的配置文件}$</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-xml" data-lang="xml"><span style="color:#999;font-weight:bold;font-style:italic">&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;</span>
<span style="color:#000080">&lt;persistence</span> <span style="color:#008080">xmlns=</span><span style="color:#d14">&#34;http://java.sun.com/xml/ns/persistence&#34;</span>
	<span style="color:#008080">xmlns:xsi=</span><span style="color:#d14">&#34;http://www.w3.org/2001/XMLSchema-instance&#34;</span>
	<span style="color:#008080">xsi:schemaLocation=</span><span style="color:#d14">&#34;http://java.sun.com/xml/ns/persistence  
</span><span style="color:#d14">    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&#34;</span>
	<span style="color:#008080">version=</span><span style="color:#d14">&#34;2.0&#34;</span><span style="color:#000080">&gt;</span>
	<span style="color:#998;font-style:italic">&lt;!--配置持久化单元 
</span><span style="color:#998;font-style:italic">		name：持久化单元名称 
</span><span style="color:#998;font-style:italic">		transaction-type：事务类型
</span><span style="color:#998;font-style:italic">		 	RESOURCE_LOCAL：本地事务管理 
</span><span style="color:#998;font-style:italic">		 	JTA：分布式事务管理 --&gt;</span>
	<span style="color:#000080">&lt;persistence-unit</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;myJpa&#34;</span> <span style="color:#008080">transaction-type=</span><span style="color:#d14">&#34;RESOURCE_LOCAL&#34;</span><span style="color:#000080">&gt;</span>
		<span style="color:#998;font-style:italic">&lt;!--配置JPA规范的服务提供商 --&gt;</span>
		<span style="color:#000080">&lt;provider&gt;</span>org.hibernate.jpa.HibernatePersistenceProvider<span style="color:#000080">&lt;/provider&gt;</span>
		<span style="color:#000080">&lt;properties&gt;</span>
			<span style="color:#998;font-style:italic">&lt;!-- 数据库驱动 --&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;javax.persistence.jdbc.driver&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;com.mysql.jdbc.Driver&#34;</span> <span style="color:#000080">/&gt;</span>
			<span style="color:#998;font-style:italic">&lt;!-- 数据库地址 --&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;javax.persistence.jdbc.url&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;jdbc:mysql://localhost:3306/jpa&#34;</span> <span style="color:#000080">/&gt;</span>
			<span style="color:#998;font-style:italic">&lt;!-- 数据库用户名 --&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;javax.persistence.jdbc.user&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;root&#34;</span> <span style="color:#000080">/&gt;</span>
			<span style="color:#998;font-style:italic">&lt;!-- 数据库密码 --&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;javax.persistence.jdbc.password&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;passw0rd&#34;</span> <span style="color:#000080">/&gt;</span>

			<span style="color:#998;font-style:italic">&lt;!--jpa提供者的可选配置：我们的JPA规范的提供者为hibernate，所以jpa的核心配置中兼容hibernate的配 --&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;hibernate.show_sql&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;true&#34;</span> <span style="color:#000080">/&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;hibernate.format_sql&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;true&#34;</span> <span style="color:#000080">/&gt;</span>
			<span style="color:#000080">&lt;property</span> <span style="color:#008080">name=</span><span style="color:#d14">&#34;hibernate.hbm2ddl.auto&#34;</span> <span style="color:#008080">value=</span><span style="color:#d14">&#34;create&#34;</span> <span style="color:#000080">/&gt;</span>
		<span style="color:#000080">&lt;/properties&gt;</span>
	<span style="color:#000080">&lt;/persistence-unit&gt;</span>
<span style="color:#000080">&lt;/persistence&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="实现保存操作">实现保存操作</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Test</span>
	<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
		<span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">		 * 创建实体管理类工厂，借助Persistence的静态方法获取
</span><span style="color:#998;font-style:italic">		 * 		其中传递的参数为持久化单元名称，需要jpa配置文件中指定
</span><span style="color:#998;font-style:italic">		 */</span>
		EntityManagerFactory factory <span style="color:#000;font-weight:bold">=</span> Persistence<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">createEntityManagerFactory</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;myJpa&#34;</span><span style="color:#000;font-weight:bold">);</span>
		<span style="color:#998;font-style:italic">//创建实体管理类
</span><span style="color:#998;font-style:italic"></span>		EntityManager em <span style="color:#000;font-weight:bold">=</span> factory<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">createEntityManager</span><span style="color:#000;font-weight:bold">();</span>
		<span style="color:#998;font-style:italic">//获取事务对象
</span><span style="color:#998;font-style:italic"></span>		EntityTransaction tx <span style="color:#000;font-weight:bold">=</span> em<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getTransaction</span><span style="color:#000;font-weight:bold">();</span>
		<span style="color:#998;font-style:italic">//开启事务
</span><span style="color:#998;font-style:italic"></span>		tx<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">begin</span><span style="color:#000;font-weight:bold">();</span>
		Customer c <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> Customer<span style="color:#000;font-weight:bold">();</span>
		c<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCustName</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;黄思聪&#34;</span><span style="color:#000;font-weight:bold">);</span>
		<span style="color:#998;font-style:italic">//保存操作
</span><span style="color:#998;font-style:italic"></span>		em<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">persist</span><span style="color:#000;font-weight:bold">(</span>c<span style="color:#000;font-weight:bold">);</span>
		<span style="color:#998;font-style:italic">//提交事务
</span><span style="color:#998;font-style:italic"></span>		tx<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">commit</span><span style="color:#000;font-weight:bold">();</span>
		<span style="color:#998;font-style:italic">//释放资源
</span><span style="color:#998;font-style:italic"></span>		em<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">close</span><span style="color:#000;font-weight:bold">();</span>
		factory<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">close</span><span style="color:#000;font-weight:bold">();</span>
	<span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><h3 id="jpa中的主键生成策略">JPA中的主键生成策略</h3>
<p>  通过annotation（注解）来映射hibernate实体的,基于annotation的hibernate主键标识为@Id, 其生成规则由@GeneratedValue设定的.这里的@id和@GeneratedValue都是JPA的标准用法。</p>
<p>JPA提供的四种标准用法为TABLE,SEQUENCE,IDENTITY,AUTO。</p>
<p>具体说明如下：</p>
<p>IDENTITY:主键由数据库自动生成（主要是自动增长型）</p>
<p>用法：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Id</span>  
   <span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy <span style="color:#000;font-weight:bold">=</span> GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">IDENTITY</span><span style="color:#000;font-weight:bold">)</span> 
    <span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>

</code></pre></td></tr></table>
</div>
</div><p>SEQUENCE：根据底层数据库的序列来生成主键，条件是数据库支持序列。</p>
<p>用法</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Id</span>  
    <span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy <span style="color:#000;font-weight:bold">=</span> GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">SEQUENCE</span><span style="color:#000;font-weight:bold">,</span>generator<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;payablemoney_seq&#34;</span><span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#3c5d5d;font-weight:bold">@SequenceGenerator</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;payablemoney_seq&#34;</span><span style="color:#000;font-weight:bold">,</span> sequenceName<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;seq_payment&#34;</span><span style="color:#000;font-weight:bold">)</span>  
<span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>
 <span style="color:#998;font-style:italic">//@SequenceGenerator源码中的定义
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#3c5d5d;font-weight:bold">@Target</span><span style="color:#000;font-weight:bold">({</span>TYPE<span style="color:#000;font-weight:bold">,</span> METHOD<span style="color:#000;font-weight:bold">,</span> FIELD<span style="color:#000;font-weight:bold">})</span>   
    <span style="color:#3c5d5d;font-weight:bold">@Retention</span><span style="color:#000;font-weight:bold">(</span>RUNTIME<span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#3c5d5d;font-weight:bold">@interface</span> SequenceGenerator <span style="color:#000;font-weight:bold">{</span>  
       <span style="color:#998;font-style:italic">//表示该表主键生成策略的名称，它被引用在@GeneratedValue中设置的“generator”值中
</span><span style="color:#998;font-style:italic"></span>       String <span style="color:#900;font-weight:bold">name</span><span style="color:#000;font-weight:bold">();</span>  
       <span style="color:#998;font-style:italic">//属性表示生成策略用到的数据库序列名称。
</span><span style="color:#998;font-style:italic"></span>       String <span style="color:#900;font-weight:bold">sequenceName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
       <span style="color:#998;font-style:italic">//表示主键初识值，默认为0
</span><span style="color:#998;font-style:italic"></span>       <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">initialValue</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> 0<span style="color:#000;font-weight:bold">;</span>  
       <span style="color:#998;font-style:italic">//表示每次主键值增加的大小，例如设置1，则表示每次插入新记录后自动加1，默认为50
</span><span style="color:#998;font-style:italic"></span>       <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">allocationSize</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> 50<span style="color:#000;font-weight:bold">;</span>  
    <span style="color:#000;font-weight:bold">}</span>

</code></pre></td></tr></table>
</div>
</div><p>AUTO：主键由程序控制</p>
<p>用法：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">	<span style="color:#3c5d5d;font-weight:bold">@Id</span>  
    <span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy <span style="color:#000;font-weight:bold">=</span> GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">AUTO</span><span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>

</code></pre></td></tr></table>
</div>
</div><p>TABLE：使用一个特定的数据库表格来保存主键</p>
<p>用法：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">	<span style="color:#3c5d5d;font-weight:bold">@Id</span>  
    <span style="color:#3c5d5d;font-weight:bold">@GeneratedValue</span><span style="color:#000;font-weight:bold">(</span>strategy <span style="color:#000;font-weight:bold">=</span> GenerationType<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">TABLE</span><span style="color:#000;font-weight:bold">,</span> generator<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;payablemoney_gen&#34;</span><span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#3c5d5d;font-weight:bold">@TableGenerator</span><span style="color:#000;font-weight:bold">(</span>name <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;pk_gen&#34;</span><span style="color:#000;font-weight:bold">,</span>  
        table<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;tb_generator&#34;</span><span style="color:#000;font-weight:bold">,</span>  
        pkColumnName<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;gen_name&#34;</span><span style="color:#000;font-weight:bold">,</span>  
        valueColumnName<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;gen_value&#34;</span><span style="color:#000;font-weight:bold">,</span>  
        pkColumnValue<span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;PAYABLEMOENY_PK&#34;</span><span style="color:#000;font-weight:bold">,</span>  
        allocationSize<span style="color:#000;font-weight:bold">=</span>1  
    <span style="color:#000;font-weight:bold">)</span> 
<span style="color:#000;font-weight:bold">private</span> Long custId<span style="color:#000;font-weight:bold">;</span>


<span style="color:#998;font-style:italic">//@TableGenerator的定义：
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#3c5d5d;font-weight:bold">@Target</span><span style="color:#000;font-weight:bold">({</span>TYPE<span style="color:#000;font-weight:bold">,</span> METHOD<span style="color:#000;font-weight:bold">,</span> FIELD<span style="color:#000;font-weight:bold">})</span>   
    <span style="color:#3c5d5d;font-weight:bold">@Retention</span><span style="color:#000;font-weight:bold">(</span>RUNTIME<span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#3c5d5d;font-weight:bold">@interface</span> TableGenerator <span style="color:#000;font-weight:bold">{</span>  
      <span style="color:#998;font-style:italic">//表示该表主键生成策略的名称，它被引用在@GeneratedValue中设置的“generator”值中
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">name</span><span style="color:#000;font-weight:bold">();</span>  
      <span style="color:#998;font-style:italic">//表示表生成策略所持久化的表名，例如，这里表使用的是数据库中的“tb_generator”。
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">table</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//catalog和schema具体指定表所在的目录名或是数据库名
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">catalog</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      String <span style="color:#900;font-weight:bold">schema</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//属性的值表示在持久化表中，该主键生成策略所对应键值的名称。例如在“tb_generator”中将“gen_name”作为主键的键值
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">pkColumnName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//属性的值表示在持久化表中，该主键当前所生成的值，它的值将会随着每次创建累加。例如，在“tb_generator”中将“gen_value”作为主键的值 
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">valueColumnName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//属性的值表示在持久化表中，该生成策略所对应的主键。例如在“tb_generator”表中，将“gen_name”的值为“CUSTOMER_PK”。 
</span><span style="color:#998;font-style:italic"></span>      String <span style="color:#900;font-weight:bold">pkColumnValue</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//表示主键初识值，默认为0。 
</span><span style="color:#998;font-style:italic"></span>      <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">initialValue</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> 0<span style="color:#000;font-weight:bold">;</span>  
      <span style="color:#998;font-style:italic">//表示每次主键值增加的大小，例如设置成1，则表示每次创建新记录后自动加1，默认为50。
</span><span style="color:#998;font-style:italic"></span>      <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">allocationSize</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> 50<span style="color:#000;font-weight:bold">;</span>  
      UniqueConstraint<span style="color:#000;font-weight:bold">[]</span> <span style="color:#900;font-weight:bold">uniqueConstraints</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">default</span> <span style="color:#000;font-weight:bold">{};</span>  
    <span style="color:#000;font-weight:bold">}</span> 

    <span style="color:#998;font-style:italic">//这里应用表tb_generator，定义为 ：
</span><span style="color:#998;font-style:italic"></span>    CREATE TABLE  <span style="color:#900;font-weight:bold">tb_generator</span> <span style="color:#000;font-weight:bold">(</span>  
      id NUMBER NOT NULL<span style="color:#000;font-weight:bold">,</span>  
      gen_name <span style="color:#900;font-weight:bold">VARCHAR2</span><span style="color:#000;font-weight:bold">(</span>255<span style="color:#000;font-weight:bold">)</span> NOT NULL<span style="color:#000;font-weight:bold">,</span>  
      gen_value NUMBER NOT NULL<span style="color:#000;font-weight:bold">,</span>  
      PRIMARY <span style="color:#900;font-weight:bold">KEY</span><span style="color:#000;font-weight:bold">(</span>id<span style="color:#000;font-weight:bold">)</span>  
    <span style="color:#000;font-weight:bold">)</span>

</code></pre></td></tr></table>
</div>
</div><h2 id="jpa的api介绍">JPA的API介绍</h2>
<h3 id="persistence对象">Persistence对象</h3>
<p>  Persistence对象主要作用是用于获取EntityManagerFactory对象的 。通过调用该类的createEntityManagerFactory静态方法，根据配置文件中持久化单元名称创建EntityManagerFactory。</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">//1. 创建 EntitymanagerFactory
</span><span style="color:#998;font-style:italic"></span><span style="color:#3c5d5d;font-weight:bold">@Test</span>
String unitName <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;myJpa&#34;</span><span style="color:#000;font-weight:bold">;</span>
EntityManagerFactory factory<span style="color:#000;font-weight:bold">=</span> Persistence<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">createEntityManagerFactory</span><span style="color:#000;font-weight:bold">(</span>unitName<span style="color:#000;font-weight:bold">);</span>

</code></pre></td></tr></table>
</div>
</div><h3 id="entitymanagerfactory">EntityManagerFactory</h3>
<p>EntityManagerFactory 接口主要用来创建 EntityManager 实例</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">//创建实体管理类
</span><span style="color:#998;font-style:italic"></span>EntityManager em <span style="color:#000;font-weight:bold">=</span> factory<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">createEntityManager</span><span style="color:#000;font-weight:bold">();</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="entitymanager">EntityManager</h3>
<p>  在 JPA 规范中, EntityManager是完成持久化操作的核心对象。实体类作为普通 java对象，只有在调用 EntityManager将其持久化后才会变成持久化对象。EntityManager对象在一组实体类与底层数据源之间进行 O/R 映射的管理。它可以用来管理和更新 Entity Bean, 根椐主键查找 Entity Bean, 还可以通过JPQL语句查询实体。</p>
<p>我们可以通过调用EntityManager的方法完成获取事务，以及持久化数据库的操作</p>
<p>方法说明：</p>
<p>  由于EntityManagerFactory 是一个线程安全的对象（即多个线程访问同一个EntityManagerFactory 对象不会有线程安全问题），并且EntityManagerFactory 的创建极其浪费资源，所以在使用JPA编程时，我们可以对EntityManagerFactory 的创建进行优化，只需要做到一个工程只存在一个EntityManagerFactory 即可</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">	getTransaction <span style="color:#000;font-weight:bold">:</span> 获取事务对象
	persist <span style="color:#a61717;background-color:#e3d2d2">：</span> 保存操作
	merge <span style="color:#a61717;background-color:#e3d2d2">：</span> 更新操作
	remove <span style="color:#a61717;background-color:#e3d2d2">：</span> 删除操作
	find<span style="color:#000;font-weight:bold">/</span>getReference <span style="color:#a61717;background-color:#e3d2d2">：</span> 根据id查询   getReference具有延迟加载作用

</code></pre></td></tr></table>
</div>
</div><h3 id="entitytransaction">EntityTransaction</h3>
<p>  在 JPA 规范中, EntityTransaction是完成事务操作的核心对象，对于EntityTransaction在我们的java代码中承接的功能比较简单</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">begin<span style="color:#a61717;background-color:#e3d2d2">：</span>开启事务
commit<span style="color:#a61717;background-color:#e3d2d2">：</span>提交事务
rollback<span style="color:#a61717;background-color:#e3d2d2">：</span>回滚事务

</code></pre></td></tr></table>
</div>
</div>
        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://laoer123.gitee.io/laoer123">Jeremy Sze</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://laoer123.gitee.io/laoer123/post/JPA/">https://laoer123.gitee.io/laoer123/post/JPA/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E4%BB%A3%E7%90%86%E6%A8%A1%E5%BC%8F/">java之设计模式_代理模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F/">java之设计模式_策略模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F/">java之设计模式_工厂模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F/">java之设计模式_单例模式</a></li>
        
        <li><a href="/laoer123/post/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F_%E6%A8%A1%E6%9D%BF%E6%A8%A1%E5%BC%8F/">java之设计模式_模板模式</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='https://laoer123.gitee.io/tags/JPA'>JPA</a></li>
                
            </ul>
            
        </div>
    </article>
    
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "yourdiscussshortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

    
    
</div>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://laoer123.gitee.io/laoer123/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://laoer123.gitee.io/laoer123">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/springcloud%E4%B8%8EspringcloudAlibaba%E6%80%BB%E7%BB%93/" title="springcloud与springcloudAlibaba总结">springcloud与springcloudAlibaba总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Seata%E6%80%BB%E7%BB%93/" title="Seata总结">Seata总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/OpenFegin%E6%80%BB%E7%BB%93/" title="OpenFegin总结">OpenFegin总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudGateWay%E6%80%BB%E7%BB%93/" title="SpringCloudGateWay总结">SpringCloudGateWay总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudRibbon/" title="SpringCloudRibbon总结">SpringCloudRibbon总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0/" title="Nacos配置注册与发现">Nacos配置注册与发现</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86%E6%BC%94%E7%A4%BA/" title="Nacos配置管理演示">Nacos配置管理演示</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E6%80%BB%E7%BB%93/" title="什么是Nacos">什么是Nacos</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97/" title="Sentinel新手指南">Sentinel新手指南</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%8E%A7%E5%88%B6%E5%8F%B0/" title="Sentinel控制台">Sentinel控制台</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/Linux/">Linux (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/NoSql%E6%95%B0%E6%8D%AE%E5%BA%93/">NoSql数据库 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloud/">SpringCloud (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibaba/">SpringCloudAlibaba (11)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibabaSpringCloud/">SpringCloudAlibaba,SpringCloud (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/docker/">docker (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/java%E5%9F%BA%E7%A1%80/">java基础 (10)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/spring/">spring (4)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E4%BA%8B%E5%8A%A1/">事务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E5%BE%AE%E6%9C%8D%E5%8A%A1/">前端微服务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6/">前端框架 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/">持续集成 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%B1%82%E6%A1%86%E6%9E%B6/">数据层框架 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库 (5)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9E%B6%E6%9E%84/">架构 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/">消息中间件 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%BC%93%E5%AD%98/">缓存 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%AE%A4%E8%AF%81/">认证 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%BF%90%E7%BB%B4/">运维 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E9%83%A8%E7%BD%B2/">部署 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Dubbo/">Dubbo</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ES6/">ES6</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElasticSearch/">ElasticSearch</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElementUI/">ElementUI</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Eureka/">Eureka</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Feign/">Feign</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JDBCTemplate/">JDBCTemplate</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JPA/">JPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JWT/">JWT</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Jenkins/">Jenkins</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E5%9F%BA%E7%A1%80/">Linux基础</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E9%85%8D%E7%BD%AE%E8%81%94%E7%BD%91/">Linux配置联网</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/MongoDB/">MongoDB</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Nacos/">Nacos</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ORACLE/">ORACLE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/OpenFegin/">OpenFegin</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/RabbitMQ/">RabbitMQ</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Seata/">Seata</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Sentinel/">Sentinel</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudGateWay/">SpringCloudGateWay</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudRibbon/">SpringCloudRibbon</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudSpringCloudAlibaba/">SpringCloud,SpringCloudAlibaba</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/VUE/">VUE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/docker/">docker</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/git/">git</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/gogs/">gogs</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/hystrix/">hystrix</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/mysql/">mysql</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nginx/">nginx</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nodeJS/">nodeJS</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/npm/">npm</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springCache/">springCache</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springDataJPA/">springDataJPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springboot/">springboot</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudbus/">springcloudbus</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudconfig/">springcloudconfig</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springdataredis/">springdataredis</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/zuul/">zuul</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1/">分布式事务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%9B%E5%BB%BA%E6%A8%A1%E5%BC%8F/">创建模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%8E%92%E5%BA%8F/">排序</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%9C%8D%E5%8A%A1%E9%95%9C%E5%83%8F%E7%9A%84%E6%9E%84%E5%BB%BA%E4%B8%8E%E9%83%A8%E7%BD%B2/">服务镜像的构建与部署</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E7%BB%93%E6%9E%84%E6%A8%A1%E5%BC%8F/">结构模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%A1%8C%E4%B8%BA%E6%A8%A1%E5%BC%8F/">行为模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%BF%90%E7%BB%B4/">运维</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.cnblogs.com/Jeremy95-Sze/" title="Jeremy Sze的博客">Jeremy Sze的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://github.com/Jeremy95-Sze" title="Jeremy Sze的github">Jeremy Sze的github</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://laoer123.gitee.io/laoer123/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
    <footer id="footer">
    <div class="container">
        &copy; 2023 <a href="https://laoer123.gitee.io/laoer123">Jeremy Sze的博客 By Jeremy Sze</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/flysnow-org/maupassant-hugo" target="_blank">maupassant</a>.
        
    </div>
</footer>


    
    <script src="//cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js" crossorigin="anonymous"></script>
        <script>(function () {
            if (!window.Diagram) return;
            const blocks = document.querySelectorAll('pre code.language-sequence');
            for (let i = 0; i < blocks.length; i++) {
                const block = blocks[i];
                
                const rootElement = block.parentNode;
                const container = document.createElement('div');
                const id = `js-sequence-diag-${i}`;
                container.id = id;
                container.className = 'align-center';
                container.setAttribute("style", "overFlow-x:auto");
                rootElement.parentNode.replaceChild(container, rootElement);

                const diagram = Diagram.parse(block.childNodes[0].nodeValue);
                diagram.drawSVG(id, window.sequenceDiagramsOptions
                    ? window.sequenceDiagramsOptions
                    : { theme: 'simple' });
            }
        })();
        </script><script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>


<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/laoer123/js/totop.js?v=0.0.0' async=""></script>

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'GA ID', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/laoer123/js/douban.js'></script>

</body>

</html>